home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / Main.as < prev    next >
Encoding:
Text File  |  2007-09-27  |  11.8 KB  |  335 lines

  1. class Main extends Library.DispatcherBase
  2. {
  3.    var mcRef;
  4.    var oHS;
  5.    var nLatestScore;
  6.    var bHSFromTitle;
  7.    var bHSScrolling;
  8.    var oTransition;
  9.    var oCodeBox;
  10.    var nHSScrollChange;
  11.    var nLoseReason;
  12.    var bTargetModeStory;
  13.    var sCurrentSection;
  14.    var sTargetSection;
  15.    var oMusicPack;
  16.    var nLatestPlayMode;
  17.    var oGame;
  18.    static var oCtrl;
  19.    static var SOUND_VOL_SOUND = 100;
  20.    static var SOUND_VOL_MUSIC = 35;
  21.    static var SOUND_CAT_SOUND = "SFX";
  22.    static var SOUND_CAT_MUSIC = "Music";
  23.    static var LOSE_REASON_TIMEOUT = 1;
  24.    static var LOSE_REASON_MOONSTONES = 2;
  25.    static var LOSE_REASON_QUIT = 3;
  26.    static var FRAME_RATE = 36;
  27.    static var SECTION_TITLE = "Title";
  28.    static var SECTION_INSTRUCTIONS = "Instructions";
  29.    static var SECTION_GAME = "Game";
  30.    static var SECTION_WIN = "Win";
  31.    static var SECTION_LOSE = "Lose";
  32.    static var SECTION_HIGHSCORE = "HighScore";
  33.    function Main(__mcRef)
  34.    {
  35.       super();
  36.       this.mcRef = __mcRef;
  37.       Main.oCtrl = this;
  38.       this.oHS = new NickHS();
  39.       this.nLatestScore = 0;
  40.       this.bHSFromTitle = true;
  41.       this.bHSScrolling = false;
  42.       this.mcRef.onEnterFrame = Library.Utils.Delegate.create(this,this.doEnterFrame);
  43.       Library.Sound.SoundManager.doInit(this.mcRef);
  44.       Library.Sound.SoundManager.setCategoryVolume(Main.SOUND_CAT_SOUND,Main.SOUND_VOL_SOUND);
  45.       Library.Sound.SoundManager.setCategoryVolume(Main.SOUND_CAT_MUSIC,Main.SOUND_VOL_MUSIC);
  46.       this.doStartPackMusic();
  47.       this.oTransition = new Library.Transition(this.mcRef.mcTransition);
  48.       this.oTransition.Listener = this;
  49.       this.doAddListener(this.oTransition);
  50.       this.oCodeBox = new CodeBox();
  51.       this.doTransitionTo(Main.SECTION_TITLE);
  52.    }
  53.    static function get Instance()
  54.    {
  55.       return Main.oCtrl;
  56.    }
  57.    function get StageRoot()
  58.    {
  59.       return this.mcRef;
  60.    }
  61.    function doEnterFrame()
  62.    {
  63.       super.doEnterFrame();
  64.       if(this.bHSScrolling)
  65.       {
  66.          this.mcRef.mcState.mcHS.txtHSNumber.scroll += this.nHSScrollChange;
  67.          this.mcRef.mcState.mcHS.txtHSName.scroll += this.nHSScrollChange;
  68.          this.mcRef.mcState.mcHS.txtHSScore.scroll += this.nHSScrollChange;
  69.       }
  70.    }
  71.    function doRollSound()
  72.    {
  73.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Button_Roll.mp3",100,1,true);
  74.    }
  75.    function doClickSound()
  76.    {
  77.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Button_Click.mp3",100,1,true);
  78.    }
  79.    function doShowHighScoresFromTitle()
  80.    {
  81.       this.bHSFromTitle = true;
  82.       this.doTransitionTo(Main.SECTION_HIGHSCORE);
  83.    }
  84.    function onBackToTitle()
  85.    {
  86.       this.doTransitionTo(Main.SECTION_TITLE);
  87.    }
  88.    function onPlayerLose(__nLoseReason)
  89.    {
  90.       this.nLoseReason = __nLoseReason;
  91.       this.doTransitionTo(Main.SECTION_LOSE);
  92.    }
  93.    function onPlayerWin()
  94.    {
  95.       this.doTransitionTo(Main.SECTION_WIN);
  96.    }
  97.    function doPlayGame(__bStoryMode)
  98.    {
  99.       this.bTargetModeStory = __bStoryMode;
  100.       this.doTransitionTo(Main.SECTION_GAME);
  101.    }
  102.    function onTransitionEvent(__nEvent, __oTransition)
  103.    {
  104.       switch(__nEvent)
  105.       {
  106.          case Library.Transition.TRANSITION_SCREEN_COVERED:
  107.             this.doUnloadSection(this.sCurrentSection);
  108.             this.doSetSection(this.sTargetSection);
  109.             Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"transition_out.mp3",60);
  110.             break;
  111.          case Library.Transition.TRANSITION_COMPLETE:
  112.       }
  113.    }
  114.    function doSoundEvent(__nEvent, __oSound)
  115.    {
  116.       if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
  117.       {
  118.          if(__oSound == this.oMusicPack)
  119.          {
  120.             delete this.oMusicPack;
  121.          }
  122.       }
  123.    }
  124.    function doSubmitScoreAndRefresh()
  125.    {
  126.       this.doSubmitScore();
  127.       this.bHSFromTitle = false;
  128.       var _loc2_ = [0.55059,0.39611,0.0533,0,0,0.20059,0.74611,0.0533,0,0,0.20059,0.39611,0.4033,0,0,0,0,0,1,0];
  129.       var _loc3_ = new flash.filters.ColorMatrixFilter(_loc2_);
  130.       this.mcRef.mcState.mcButtons.btnSubmitHS.filters = [_loc3_];
  131.       this.mcRef.mcState.mcButtons.btnSubmitHS.enabled = false;
  132.    }
  133.    function doSubmitAndListScore()
  134.    {
  135.       this.doSubmitScore();
  136.       this.bHSFromTitle = false;
  137.       this.doTransitionTo(Main.SECTION_HIGHSCORE);
  138.    }
  139.    function doStartPackMusic()
  140.    {
  141.       if(this.oMusicPack == undefined)
  142.       {
  143.          this.oMusicPack = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_MUSIC,"Packaging.wav",0,999999);
  144.          this.oMusicPack.doAddListener(this);
  145.       }
  146.       this.oMusicPack.doFadeTo(100);
  147.    }
  148.    function doStopPackMusic()
  149.    {
  150.       if(this.oMusicPack != undefined)
  151.       {
  152.          this.oMusicPack.doFadeTo(0);
  153.       }
  154.    }
  155.    function doStopScrollHsList()
  156.    {
  157.       this.bHSScrolling = false;
  158.    }
  159.    function doStartScrollHsList(__nChange)
  160.    {
  161.       this.bHSScrolling = true;
  162.       this.nHSScrollChange = __nChange;
  163.    }
  164.    function doInstructionPageChange(__nChange)
  165.    {
  166.       this.mcRef.mcState.gotoAndStop(this.mcRef.mcState._currentframe + __nChange);
  167.       this.doSetUpInstructions();
  168.    }
  169.    function get HSM()
  170.    {
  171.       return this.oHS;
  172.    }
  173.    function get CodeBoxManager()
  174.    {
  175.       return this.oCodeBox;
  176.    }
  177.    function doSubmitScore()
  178.    {
  179.       this.oHS.bSubmitHS = true;
  180.       this.oHS.submitScore(this.nLatestScore);
  181.       this.mcRef.mcState.btnSubmitHS._visible = false;
  182.    }
  183.    function doSetUpTitle()
  184.    {
  185.       this.mcRef.mcState.btnPlayStory.onRelease = Library.Utils.Delegate.create(this,this.doPlayGame,true);
  186.       this.mcRef.mcState.btnPlayUser.onRelease = Library.Utils.Delegate.create(this,this.doPlayGame,false);
  187.       this.mcRef.mcState.btnInstructions.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_INSTRUCTIONS);
  188.       this.mcRef.mcState.btnViewHS.onRelease = Library.Utils.Delegate.create(this,this.doShowHighScoresFromTitle);
  189.       this.oCodeBox.setBox(this.mcRef.mcState.mcCode);
  190.    }
  191.    function doSetUpHS()
  192.    {
  193.       if(this.bHSFromTitle)
  194.       {
  195.          this.mcRef.mcState.mcButtons.gotoAndStop("Back");
  196.          this.mcRef.mcState.mcButtons.btnBack.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_TITLE);
  197.       }
  198.       else
  199.       {
  200.          this.mcRef.mcState.mcButtons.gotoAndStop("PlayAgain");
  201.          this.mcRef.mcState.mcButtons.btnPlayAgain.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_GAME);
  202.       }
  203.       if(!this.bHSFromTitle)
  204.       {
  205.          this.mcRef.mcState.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nLatestScore,9);
  206.       }
  207.       else
  208.       {
  209.          this.mcRef.mcState.txtScore._visible = false;
  210.          this.mcRef.mcState.mcScoreLabel._visible = false;
  211.       }
  212.       this.oHS.setHSBoard(this.mcRef.mcState.mcHS);
  213.       this.oHS.getScores();
  214.       if(this.oHS.bSubmitHS || !this.oHS.getIsLoggedIn() || this.bHSFromTitle)
  215.       {
  216.          this.mcRef.mcState.mcButtons.btnSubmitHS.useHandCursor = false;
  217.          var _loc2_ = [0.55059,0.39611,0.0533,0,0,0.20059,0.74611,0.0533,0,0,0.20059,0.39611,0.4033,0,0,0,0,0,1,0];
  218.          var _loc3_ = new flash.filters.ColorMatrixFilter(_loc2_);
  219.          this.mcRef.mcState.mcButtons.btnSubmitHS.filters = [_loc3_];
  220.          this.mcRef.mcState.mcButtons.btnSubmitHS.enabled = false;
  221.       }
  222.       else
  223.       {
  224.          this.mcRef.mcState.mcButtons.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitScoreAndRefresh);
  225.       }
  226.       this.mcRef.mcState.btnHaut.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,-1);
  227.       this.mcRef.mcState.btnBas.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,1);
  228.       this.mcRef.mcState.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  229.       this.mcRef.mcState.btnHaut.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  230.       this.mcRef.mcState.btnHaut.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  231.       this.mcRef.mcState.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  232.       this.mcRef.mcState.btnBas.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  233.       this.mcRef.mcState.btnBas.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  234.    }
  235.    function doSetUpLose()
  236.    {
  237.       this.doSetUpWinLoseShared();
  238.       if(this.nLatestPlayMode == BaseLevelData.LEVEL_TYPE_USER)
  239.       {
  240.          this.mcRef.mcState.mcScore._visible = false;
  241.       }
  242.       this.mcRef.mcState.mcReason.gotoAndStop(this.nLoseReason);
  243.    }
  244.    function doSetUpWin()
  245.    {
  246.       this.doSetUpWinLoseShared();
  247.    }
  248.    function doSetUpWinLoseShared()
  249.    {
  250.       this.bHSFromTitle = false;
  251.       if(this.nLatestPlayMode == BaseLevelData.LEVEL_TYPE_STORY)
  252.       {
  253.          this.mcRef.mcState.btnViewHS.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_HIGHSCORE);
  254.          if(this.oHS.getIsLoggedIn())
  255.          {
  256.             this.mcRef.mcState.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitAndListScore);
  257.          }
  258.          else
  259.          {
  260.             this.mcRef.mcState.btnSubmitHS._visible = false;
  261.             this.mcRef.mcState.mcCorde1._visible = false;
  262.          }
  263.       }
  264.       else
  265.       {
  266.          this.mcRef.mcState.btnViewHS._visible = false;
  267.          this.mcRef.mcState.btnSubmitHS._visible = false;
  268.          this.mcRef.mcState.mcCorde1._visible = false;
  269.          this.mcRef.mcState.mcCorde2._visible = false;
  270.          this.mcRef.mcState.mcSign._visible = false;
  271.       }
  272.       this.mcRef.mcState.mcScore.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nLatestScore,9);
  273.       this.mcRef.mcState.btnPlayAgain.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_GAME);
  274.    }
  275.    function doSetUpInstructions()
  276.    {
  277.       this.mcRef.mcState.stop();
  278.       this.mcRef.mcState.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_TITLE);
  279.       this.mcRef.mcState.btnNext.onRelease = Library.Utils.Delegate.create(this,this.doInstructionPageChange,1);
  280.       this.mcRef.mcState.btnBack.onRelease = Library.Utils.Delegate.create(this,this.doInstructionPageChange,-1);
  281.    }
  282.    function doCreateGame()
  283.    {
  284.       this.oGame = new Game(this.mcRef.mcState,this.bTargetModeStory);
  285.    }
  286.    function doUnloadGame()
  287.    {
  288.       this.nLatestPlayMode = this.oGame.LevelType;
  289.       if(this.nLatestScore > this.oGame.Score)
  290.       {
  291.          this.oHS.bSubmitHS = false;
  292.       }
  293.       this.nLatestScore = this.oGame.Score;
  294.       this.oGame.doDestroy();
  295.    }
  296.    function doSetSection(__sSection)
  297.    {
  298.       this.sCurrentSection = __sSection;
  299.       this.mcRef.gotoAndStop(this.sCurrentSection);
  300.       switch(this.sCurrentSection)
  301.       {
  302.          case Main.SECTION_WIN:
  303.             this.doSetUpWin();
  304.             break;
  305.          case Main.SECTION_LOSE:
  306.             this.doSetUpLose();
  307.             break;
  308.          case Main.SECTION_INSTRUCTIONS:
  309.             this.doSetUpInstructions();
  310.             break;
  311.          case Main.SECTION_TITLE:
  312.             this.doSetUpTitle();
  313.             break;
  314.          case Main.SECTION_GAME:
  315.             this.doCreateGame();
  316.             break;
  317.          case Main.SECTION_HIGHSCORE:
  318.             this.doSetUpHS();
  319.       }
  320.    }
  321.    function doUnloadSection(__sSection)
  322.    {
  323.       if(__sSection === Main.SECTION_GAME)
  324.       {
  325.          this.doUnloadGame();
  326.       }
  327.    }
  328.    function doTransitionTo(__sSection)
  329.    {
  330.       this.sTargetSection = __sSection;
  331.       this.oTransition.doStart();
  332.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"transition_in.mp3",60);
  333.    }
  334. }
  335.